﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
using Baimasoft.Manage.SqlServerDAL;

public partial class BBS_BbsRegisterUser : System.Web.UI.Page
{
    string str1, str2, str3, str4, str5, str6, str7, str8;
    user MyUser = new user();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
        }
    }

    /// <summary>
    /// 保存注册信息
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Regi_Click(object sender, EventArgs e)
    {
        str1 = UserID.Text.ToString().Trim();
        str2 = password1.Text.ToString().Trim();
        if (Boy.Checked)
        {
            str3 = "1";//1表示男性，0表示女性。
        }
        else
        {
            str3 = "0";
        }
        str4 = Tel.Text.ToString().Trim();
        str5 = Email.Text.ToString().Trim();
        str6 = Address.Text.ToString().Trim();
        str7 = SignNature.Text.ToString().Trim();
        str8 = password2.Text.ToString().Trim();
        string Number = @"^[0-9a-zA-Z\u4E00-\u9FA5]+$";

        if (!Regex.IsMatch(str1, Number))
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('用户名只能有中文、字母和数字组成！');</script>");
        }
        else if (str1 == "")
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('用户名不能为空！');</script>");
        }
        else if (str2 != str8)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('两次密码不一致，请重新输入密码！');</script>");
        }
        else if (str4 == "")
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('电话号码不能为空！');</script>");
        }
        else if (str5 == "")
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('请填写正确的邮箱！');</script>");
        }
        else if (str6 == "")
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('地址不能为空！');</script>");
        }
        else
        {
            int back = MyUser.JudgeRegUserID (str1);
            if (back == 1)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('对不起，该用户名已被注册！');</script>");
            }
            else
            {
                int res = MyUser .SaveBbsUser (str1, str2, str3, str4, str5, str6, str7);
                if (res == 1)
                {
                    Response.Cookies["jusername"].Value = "" + str1 + "";
                    Response.Cookies["jpassword"].Value = "" + str2 + "";
                    Response.Cookies["jpower"].Value = "42";
                    Response.Cookies["jhidden"].Value = "0";
                    ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('恭喜您，已注册成功！');location.href='index.aspx';</script>");
                }
                else
                    ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('注册失败！');</script>");
            }
        }
    }

    /// <summary>
    /// 重填
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Reset_Click(object sender, EventArgs e)
    {
        UserID.Text = "";
        password1.Text = "";
        Tel.Text = "";
        Email.Text = "";
        Address.Text = "";
        SignNature.Text = "";
    }
}
